package com.lagou;

import com.lagou.client.RpcConsumerV2;
import com.lagou.service.IStudentService;
import com.lagou.service.IUserService;
import com.lagou.vo.Student;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConsumerApplication.class)
public class test {

    @Test
    public void testClient() throws Exception{
        //1.创建代理对象
        IUserService service = (IUserService) RpcConsumerV2.createProxy(IUserService.class);

        //2.循环给服务器写数据
//        while (true){
//            String result = service.sayHello("are you ok !!");
//            System.out.println(result);
//            Thread.sleep(2000);
//        }
        String result = service.sayHello("are you ok !!");
        System.out.println(result);
    }

    @Test
    public void testStudent() throws Exception{
        IStudentService service = (IStudentService)RpcConsumerV2.createProxy(IStudentService.class);
        System.out.println("客户端执行findAllStudents方法：");
        List<Student> studentList = service.findAllStudents();
        for (Student student : studentList) {
            System.out.println("客户端收到findAllStudents结果："+student.toString());
        }
        System.out.println("客户端执行findOneStudent方法：");
        Student oneStudent = service.findOneStudent("123");
        System.out.println("客户端收到findOneStudent结果："+oneStudent.toString());

        System.out.println("客户端执行updateStudent方法：");
        service.updateStudent("123");
        System.out.println("客户端执行updateStudent成功");
    }
}
